// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: chensili

#pragma once

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "coin2/exchange/base/symbology/spot_product.h"
#include "coin2/exchange/base/symbology/util.h"
#include "coin2/exchange/upbit/symbology/currency.h"
#include "coin2/exchange/upbit/symbology/product_util.h"

namespace coin2::exchange::upbit::symbology {

class UpbitProduct
    : public base::symbology::SpotProduct<UpbitCurrency, UpbitProduct>,
      public base::symbology::ProductFromStrMixin<UpbitProduct> {
 public:
  typedef SpotProduct<UpbitCurrency, UpbitProduct> BaseProduct;

  UpbitProduct(
      const UpbitCurrency& base,
      const UpbitCurrency& quote) :
    SpotProduct(
        base,
        quote,
        util::ToUpbitNativeProduct(base, quote),
        util::ToUpbitNativeProduct(base, quote),
        base::market::ExchangeType::Upbit) { }

 public:
  static std::unique_ptr<UpbitProduct> FromNativeStrImpl(
      const std::string& native_product,
      int64_t resolve_timestamp) {
    std::unique_ptr<UpbitCurrency> base_ptr;
    std::unique_ptr<UpbitCurrency> quote_ptr;
    bool success = util::ParseUpbitNativeProduct(
        native_product, resolve_timestamp, &base_ptr, &quote_ptr);
    if (success) {
      return std::make_unique<UpbitProduct>(*base_ptr, *quote_ptr);
    } else {
      return { };
    }
  }
};

}  // namespace coin2::exchange::upbit::symbology
